package com.coocaa.ops.admin.v1.dict.provider;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.coocaa.ops.admin.v1.dict.biz.DictInfoBizImpl;
import com.coocaa.ops.admin.v1.dict.model.DictInfoQueryModel;
import com.coocaa.ops.common.core.base.model.PageResultModel;
import com.coocaa.ops.common.core.base.util.PageQueryUtil;
import com.coocaa.ops.common.core.biz.dict.entity.DictInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Author : bijiahao
 * @Date : 2018/6/19.
 * @Description: 数据字典 查询提供者接口实现
 * <p> </p>
 */
@Service
public class DictInfoQueryProviderImpl implements IDictInfoQueryProvider {
    @Autowired
    private DictInfoBizImpl dictInfoBiz;

    public DictInfoBizImpl getDictInfoBiz() {
        return dictInfoBiz;
    }

    @Override
    public PageResultModel<DictInfoEntity> listPage(DictInfoQueryModel model) {
        Map params = PageQueryUtil.getFilterMap(model);
        int total = dictInfoBiz.getMapper().selectCountPage(params);
        List<DictInfoEntity> resultList = null;
        if (total > 0) {
            resultList = dictInfoBiz.getMapper().queryCommonPageList(params);
        }
        return PageResultModel.getPageResultModel(total, resultList);
    }

    @Override
    public List<DictInfoEntity> queryByCategory(String dictCategory) {
        QueryWrapper<DictInfoEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("flag", 1);
        wrapper.lambda().eq(DictInfoEntity::getDictCategory, dictCategory);
        return dictInfoBiz.getMapper().selectList(wrapper);
    }
}
